﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Agile.Engine.Plus
{
    public class SchemaCreator
    {
        public string Dictionary { get; set; }

        public void CreateSchema(System.Data.DataSet data)
        {
            foreach (var r in data.Tables["SYS_TABLES"].AsEnumerable().AsParallel())
            {
                var type = r[2].ToString();

                var n = r[0].ToString();
                var t = data.Tables[n];

                for (var i = 0; i < t.Columns.Count; i++)
                {
                    t.Columns[i].Caption = t.Columns[i].ColumnName;
                    t.Columns[i].ColumnName = "col" + i.ToString();
                }
                if(!System.IO.Directory.Exists(Dictionary) )
                    System.IO.Directory.CreateDirectory(Dictionary);
                t.WriteXml(System.IO.Path.Combine(Dictionary, t.TableName + ".xml"), XmlWriteMode.WriteSchema, true);
            }
        }
    }
}
